package cn.com.sp.demo.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.sp.demo.bean.User;
import cn.com.sp.demo.mapper.UserMapper;
import cn.com.sp.demo.service.IUserService;

@Service
public class UserServcie implements IUserService {

	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User getUserById(Integer id) {
		
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public void addUser(User user) {
		Integer userId = userMapper.getMaxUserId();
		if(null == userId){
			System.out.println("为空");
			userId = 0;
		}
		user.setUserId(userId + 1);
		userMapper.insert(user);
	}

	@Override
	public void deleteUser(Integer id) {
		userMapper.deleteByPrimaryKey(id);
	}

	@Override
	public User getUser(Integer id) {
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public void updateUser(User user) {
		userMapper.updateByPrimaryKey(user);
	}

}
